package core

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

type ErrResponse struct {
	Code      int    `json:"code"`
	Message   string `json:"message"`
	Reference string `json:"reference,omitempty"`
}
type Error struct {
	Http_Code int
	Err       ErrResponse
}

func WithCode(http_code int, code int, er string) *Error {
	return &Error{
		Http_Code: http_code,
		Err:       ErrResponse{code, er, ""}}
}

func WriteResponse(c *gin.Context, err *Error, data interface{}) {
	if err != nil {
		c.JSON(err.Http_Code, err.Err)
		return
	}
	c.JSON(http.StatusOK, data)
}
